
<include file="Common:address"/>
<link rel="stylesheet" href="/Static/mobile/vant/index.css">
<script src="/Static/mobile/vant/vue.min.js"></script>
<script src="/Static/mobile/vant/vant.min.js?i=1"></script>
<div id="dailiapp" style="margin-bottom:100px;">
    <van-badge-group :active-key="activeKey" style="width:98px;float: left;">
        <van-badge title="商品列表"></van-badge>
    </van-badge-group>
    <div v-if="activeKey!==''" style="float: left;width: calc(100% - 100px)">
        <template  v-for="item in list">
            <van-cell-group>
                <van-cell>
                    <span slot="title" style="font-size:15px;">{{item.goods_name}}
                        <van-stepper min="0" style="position:absolute;right:10px;bottom:10px;font-size:15px;" v-model="item.num" ></van-stepper>
                    </span>
                    <img slot="icon" width="80" height="80" :src="item.goods_pic"/>
                </van-cell>
            </van-cell-group>
        </template>
    </div> 

    <van-cell-group style="clear: both;margin-top:2em;">
        <van-cell v-if="memberinfo.money>0" title="<?=C(YONGJIN_NAME)?>余额:<?=$memberinfo[money]?>" center>
            <van-switch v-model="use.money" size="25px"></van-switch>
        </van-cell>
    </van-cell-group>

    <van-submit-bar
        :price="grade==3?20000:200000"
        button-text="提交订单"
        @submit="onSubmit"
    ></van-submit-bar>
    <van-submit-bar
        :price="grade==3?20000:200000"
        button-text="提交订单"
        @submit="onSubmit"
    >  
    <span slot="tip">
        <span v-if="grade==3">
            升级店长，任意选择2套产品
        </span>
        <span v-if="grade==4">
            升级资深店长，任意选择5套产品
        </span>
    </span>
    </van-submit-bar>
</div>

<script>
    var dailiapp = new Vue({
        el: '#dailiapp',
        data: {
            searchValue:'',
            searchResult: [],
            activeKey:0,
            provinceList: [],
            use: {
                money: false
            },
            grade:<?=get('grade',3)?>,
            applyData: {
                area_name:'北京',
                area_id: 100,
                money: 120000,
            },
            memberinfo:JSON.parse('<?php echo json_encode($memberinfo);?>'),
            list:[]
        },
        created: function () {
            this.getGoodsList(this.grade);
        },
        methods: {
            getGoodsList: function (grade) {
                var self = this;
                $.get('/mobile/cart/getGoodsList?grade='+grade).then(function(res){
                    if(res.ret==0) {
                        self.list = [];
                        for(var i=0;i<res.data.length;i++) {
                            self.list.push(res.data[i]);
                        }
                    }else{
                        self.list = [];
                    }
                })
            },
            apply: function (data) {
                this.applyData = data;
                this.showDialog = true;
            },
            onSubmit: function () {
                var data = {
                    address_id:addressapp.chosenAddressId,
                    goodslist:this.list,
                    grade_id: this.grade,
                    use_yongjin:this.use.money?1:0
                };
                $.ajax({
                    type:'post',
                    url: '/mobile/orderadd/daili',
                    data: data,
                }).then(function (res) {
                    if(res.ret==1) {
                        showerror(res.msg);
                    }else{
                        showsuccess(res.msg,res.url);
                    }
                })
            },
        }
    })
</script>
<style>
#dailiapp .van-button--danger{
    background-color: #e6207a;
    border: 1px solid #e6207a;
}
#dailiapp .van-badge--select {
    border-color:#e6207a;
}
</style>